﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Enterprise.Data.Doc;
using Enterprise.Infrastructure;
using Enterprise.Model.Doc;
using System.Data;
using Enterprise.Model.Module;
using Enterprise.Service.Module;
namespace Enterprise.Service.Doc
{
    public class DocArticleService
    {
        /// <summary>
        /// 首页调用
        /// </summary>
        /// <param name="classid"></param>
        /// <returns></returns>
        public static string GetArticleListForIndex(int classid,int nums, Enterprise.Service.Translation.Language lang)
        {
            StringBuilder sb = new StringBuilder();
            DocService dService = new DocService();
            ModuleService mService = new ModuleService();
            string swhere = ""+classid;
            List<ModuleEntity> mlist = mService.ModuleList().Where(p => p.MPARENTID == classid).OrderBy(p => p.MORDERBY).ToList();
            string cmd = "";
            if (mlist.Count > 0)
            {
                foreach (var var in mlist)
                {
                    swhere += "," + var.MODULEID;
                }
                cmd = "select * from DOC_ARTICLES where CLASSID in (" + swhere + ") order by PUBDATE desc";
            }
            else
            {
                cmd = "select * from DOC_ARTICLES where CLASSID =" + classid + " order by PUBDATE desc";
            }

            var list = dService.DocQianshouList(dService.DocArticleList(cmd)).Take(nums).ToList();
            foreach (var var in list)
            {
                sb.Append("<div class=\"bottomlinks\">");
                if (lang == Service.Translation.Language.zhcn)
                    sb.Append("<a href=\"\\Modules\\doc\\details.aspx?id=" + var.ID + "\" target=\"_blank\">" + var.TITLE.CutString(40) + "</a>");
                else
                    sb.Append("<a href=\"\\Modules\\doc\\details.aspx?id=" + var.ID + "\" target=\"_blank\">" + var.TITLERU.CutString(70) + "</a>");
                sb.Append("</div>");
            }
            return sb.ToString();
        }


    }
}
